﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;
using System.Threading;
using StructureMap;
using Universum.Infrastructure.Security;

namespace Universum.Infrastructure.Utils.Security
{
	public class UniversumPrincipal : IPrincipal
	{
		private readonly IIdentity _identity;
				
		public UniversumPrincipal(IIdentity identity
			
			)
		{
			_identity = identity;
			
		}

		#region IPrincipal Members

		public IIdentity Identity
		{
			get { return _identity; }
		}

		public static UniversumPrincipal Current
		{
			get
			{
				if (HttpContext.Current != null)
				{
					return HttpContext.Current.User as UniversumPrincipal;
				}
				return Thread.CurrentPrincipal as UniversumPrincipal;
			}
		}

		public bool IsInRole(string role)
		{
			
			return ObjectFactory.GetInstance<IRoleService>().IsInRole(role);
		}

		#endregion
	}
}
